﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Web;
using Chbl.Models;

namespace Chbl.DAL
{
    public class ChblDb : DbContext
    {
        public DbSet<Season> Seasons { get; set; }
        public DbSet<Team> Teams { get; set; }
        public DbSet<Division> Divisions { get; set; }
        public DbSet<SeasonDivision> SeasonDivisions { get; set; }
        public DbSet<Member> Members { get; set; }
        public DbSet<Player> Players { get; set; }
        public DbSet<TeamPlayer> TeamPlayers { get; set; }
        public DbSet<Game> Games { get; set; }
        public DbSet<Settings> Settings { get; set; }
        public DbSet<Article> Articles { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
            modelBuilder.Entity<Game>().HasRequired(g => g.RoadTeam).WithMany().WillCascadeOnDelete(false);
            modelBuilder.Entity<Team>().HasMany(t => t.SeasonDivisions).WithMany(s => s.Teams)
                .Map(t => t.MapLeftKey("TeamId").MapRightKey("SeasonDivisionId"));
        }

        
     }
}